/* eslint-disable @typescript-eslint/no-unused-vars */
import { useCallback, useRef } from 'react';

export default function useRefState<T>(initValue: T) {
  const ref = useRef<T>(initValue);
  const setState = useCallback((arg: ((prev: T) => T) | T) => {
    if (arg instanceof Function) {
      ref.current = arg(ref.current);
      return;
    }

    ref.current = arg;
  }, []);

  return [ref, setState] as const;
}
